﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Assignment2
{
    // price cut event delegate
    public delegate void PriceCutEvent(Int32 price);

    // Order notification event delegate
    // Used by the MultiCellBuffer to notify subscribers
    // when an order is ready for processing.
    public delegate void OrderNotification();

    // price cut event delegate
    public delegate void RetailerShutdownEvent();

    // price cut event delegate
    public delegate void OrderProcessingEvent(Order order);

    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Enter number of retailers (1-10):");
            string input = Console.ReadLine();
            int numberOfRetailers = Int16.Parse(input);

            // initialize the logger
            Logger.create_log("output_log.log");
            OrderReceiptLog.create_log("orders.log");
            
            Console.WriteLine("Main thread has started");
            Logger.log_message("Main thread has started");
            int numberOfCells = 4;
            MultiCellBuffer.init(numberOfCells);

            // start the chicken farm
            ChickenFarm chicken_farm = new ChickenFarm();
            Thread server_thread =
                new Thread(new ThreadStart(chicken_farm.start));
            server_thread.Start();

            for (int i = 0; i < numberOfRetailers; i++)
            {
                //Thread.Sleep(10);
                new Thread(new ThreadStart(new Retailer(i).RetailerFunc)).Start();
            }


            Console.ReadLine();
            Logger.log_message("AverageResponseTime: " + Order.getAverageResponseTime().ToString());
            Console.WriteLine("AverageResponseTime: " + Order.getAverageResponseTime().ToString());
            
            Console.WriteLine("Press enter to terminate program");
            Console.ReadLine();
            Console.WriteLine("Main thread has finished");

            Logger.close_log();
            OrderReceiptLog.close_log();
        }


    }
}
